<template>
	<!--收款设置页面-->
	<view class="community">
		<view class="head_bg" style="position: relative;"></view>
		<view class="big_box" style="margin-top: -160rpx;">
			 <!-- <view v-if="info.payment_method!=null" class="guide_box">
				<view class="join_li">
					<text class="join_li_text">收款方式</text>
					<radio-group class="join_li_radio" @change="radioChange">
						<radio value="0" class="form_radio" :class="info.payment_method==0?'checked':''" :checked="info.payment_method==0"/><text class="join_text">微信转账</text>
						<radio value="1" class="form_radio" :class="info.payment_method==1?'checked':''" :checked="info.payment_method==1"/><text class="join_text">个人银行</text>
						<radio value="2" class="form_radio" :class="info.payment_method==2?'checked':''" :checked="info.payment_method==2"/><text class="join_text">企业银行</text>
					</radio-group>
				</view>
				<view class="join_li" v-if="info.payment_method!=0">
					<text v-if="info.payment_method==1" class="join_li_text">收款人</text>
					<text v-if="info.payment_method==2" class="join_li_text">企业名称</text>
					<input v-if="info.payment_method!=0" class="join_li_input" @input="getname" type="text" v-model="info.payee" placeholder="请输入收款人" />
				</view>	
				<view class="join_li" v-if="info.payment_method!=0">
					<text class="join_li_text">收款银行</text>
					<input class="join_li_input" type="text" @input="getbank" v-model="info.receiving_bank" placeholder="请输入收款银行" />
				</view>	
				<view class="join_li">
					<text v-if="info.payment_method==0" class="join_li_text">收款码</text>
					<text v-else class="join_li_text">收款账户</text>
					<input class="join_li_input" type="text" value="" @input="getzh" v-model="info.collection_account_no" placeholder="请输入收款账户" />
				</view>
				<view class="join_li" v-if="info.payment_method!=0">
					<text class="join_li_text">收款人电话</text>
					<input class="join_li_input" type="text" value="" @input="getphone" v-model="info.payee_phone" placeholder="请输入收款人电话" />
				</view>
			</view> -->
			<form @submit="formSubmit" @reset="">
				<view class="guide_box">
					<view class="join_li">
						<text class="join_li_text">收款方式</text>
						<radio-group class="join_li_radio" @change="radioChange">
							<radio class="form_radio" :class="index==0?'checked':''" :checked="index == 0" checked="" value="0"/><text class="join_text">微信</text>
							<radio class="form_radio" :class="index==1?'checked':''" :checked="index == 1" value="1"/><text class="join_text">个人银行</text>
							<radio class="form_radio" :class="index==2?'checked':''" :checked="index == 2" value="2"/><text class="join_text">对公</text>
						    <radio class="form_radio" :class="index==3?'checked':''" :checked="index == 3" value="3"/><text class="join_text">支付宝</text>
						</radio-group>
					</view>
					<view v-if="index==0">
						<view class="join_li">
							<text class="join_li_text">收款账号</text>
							<input class="join_li_input" type="text" v-model="openid" placeholder="请输入收款账户" />
						</view>
					</view>
					<view v-if="index==1">
						<view class="join_li">
							<text class="join_li_text">收款人</text>
							<input class="join_li_input" type="text" v-model="info.payee" placeholder="请输入收款人" />
						</view>
						<view class="join_li">
							<text class="join_li_text">收款银行</text>
							<input class="join_li_input" type="text" v-model="info.receiving_bank" placeholder="请输入收款银行" />
						</view>
						<view class="join_li">
							<text class="join_li_text">收款账户</text>
							<input class="join_li_input" type="text" v-model="info.collection_account_no" placeholder="请输入收款账户" />
						</view>
						<view class="join_li">
							<text class="join_li_text">收款人电话</text>
							<input class="join_li_input" type="text" v-model="info.payee_phone" placeholder="请输入收款人电话" />
						</view>
					</view>
					<view v-if="index==2">
						<view class="join_li">
							<text class="join_li_text">企业名称</text>
							<input class="join_li_input" type="text" v-model="info.payee" placeholder="请输入收款人" />
						</view>
						<view class="join_li">
							<text class="join_li_text">收款银行</text>
							<input class="join_li_input" type="text" v-model="info.receiving_bank" placeholder="请输入收款银行" />
						</view>
						<view class="join_li">
							<text class="join_li_text">收款账户</text>
							<input class="join_li_input" type="text" v-model="info.collection_account_no" placeholder="请输入收款账户" />
						</view>
						<view class="join_li">
							<text class="join_li_text">收款人电话</text>
							<input class="join_li_input" type="text" v-model="info.payee_phone" placeholder="请输入收款人电话" />
						</view>
					</view>
					<view v-if="index==3">
						<view class="join_li">
							<text class="join_li_text">收款账户</text>
							<input class="join_li_input" type="text" v-model="info.collection_account_no" placeholder="请输入收款人" />
						</view>
						<view class="join_li">
							<text class="join_li_text">收款人电话</text>
							<input class="join_li_input" type="text" v-model="info.payee_phone" placeholder="请输入收款人电话" />
						</view>
					</view>
					
					<!-- <view class="join_li" v-if="index!=0">
						<text v-if="index==3" class="join_li_text">收款账号</text>
						<text v-if="index==1" class="join_li_text">收款人</text>
						<text v-if="index==2" class="join_li_text">企业名称</text>
						<input class="join_li_input" name="payee" type="text" v-model="info.payee" placeholder="请输入收款人" />
					</view>	
					<view class="join_li" v-if="index!=0 && index!=3">
						<text class="join_li_text">收款银行</text>
						<input class="join_li_input" type="text" name="receiving_bank" v-model="info.receiving_bank" placeholder="请输入收款银行" />
					</view>	
					<view class="join_li" v-if="index!=3">
						<text v-if="index!=0" class="join_li_text">收款账号</text>
						<text v-else class="join_li_text">收款账户</text>
						<input v-if="index==0" class="join_li_input" type="text" name="collection_account_no" v-model="openid" placeholder="请输入收款账户" />
						<input v-else class="join_li_input" type="text" name="collection_account_no" v-model="info.collection_account_no" placeholder="请输入收款账户" />
					</view>
					<view class="join_li" v-if="index!=0">
						<text class="join_li_text">收款人电话</text>
						<input class="join_li_input" type="text" maxlength="11" name="payee_phone" v-model="info.payee_phone" placeholder="请输入收款人电话" />
					</view> -->
				</view>
				<!-- <button type="button" class="submit_btn" form-type="">保存</button> -->
				<view class="foot">
				   <button type="button" class="cu-btn block bg-blue lg" @tap="submit()">提交</button>
				</view>
			</form>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				info:{
					"payment_method":null,//收款方式 0 微信 1 个人银行 2 对公//收款人
					"payee":null,//收款人
					"receiving_bank":null,//收款银行
					"collection_account_no":null,//收款账号
					"payee_phone":null,//"收款人电话"
				},
				index:1,
				openid:[]
			}
		},
		onShow() {
			this.getdata();
			this.openid=uni.getStorageSync("openid")
			console.log(this.openid)
			// this.openid="rwerwerwr324343";
		},
		methods: {
			//获取收款设置信息
			getdata(){
				let that=this;
				that.http.tokenreq({
					url: 'user/v1/getcollection'
				}).then((res) => {
					let e=res.data;
					console.log("e="+JSON.stringify(e));
					if(e.code==0 && e.success){
						that.info=e.data;
						that.index=e.data.payment_method;
					}
				})
			},
			radioChange(e){
				this.index=e.target.value;
			},
			submit(e){
				if(this.info.collection_account_no==null || this.info.collection_account_no==''){
				   uni.showToast({
				   	icon: 'none',
				       title: '请填写收款账号'
				   });
				   return; 
				}
				if(this.index!=0 && (this.info.payee==null || this.info.payee=='')){
				   uni.showToast({
				   	icon: 'none',
				       title: '请填写收款人'
				   });
				   return; 
				}
				if(this.index!=0 && (this.info.receiving_bank==null || this.info.receiving_bank=='')){
				   uni.showToast({
				   	icon: 'none',
				       title: '请填写收款银行'
				   });
				   return; 
				}
				if(this.index!=0 && (this.info.payee_phone==null || this.info.payee_phone=='')){
				   uni.showToast({
				   	icon: 'none',
				       title: '请填写收款电话'
				   });
				   return; 
				}
				this.http.tokenreq({
					url: 'user/v1/setupcollection',
					data: {
				    "payment_method":this.index,
					"payee":this.info.payee,
					"receiving_bank":this.info.receiving_bank,
					"collection_account_no":this.info.collection_account_no,
					"payee_phone":this.info.payee_phone,
					}
				}).then((res) => {
					let e=res.data;
					if(e.code==0 && e.success){
					    uni.showModal({
					    	content: e.message,
					    	showCancel:false,
					    	success: function (res) {
					    		if (res.confirm) {
					    			uni.redirectTo({
					    				url:'/pages/user/my/my'
					    			});
					    		}
					    	}
					    });
					}
				})
			 
			}
				
		}
	}
</script>
<style>
	.join_li{
		line-height:100rpx;
	}
	.foot{
		position: fixed;
		left: 0;
		bottom: 0;
		width:100%;
	}
</style>